/*
 * @Author: DUST
 * @Date: 2023-06-27 14:56:37
 * @LastEditors: DUST
 * @LastEditTime: 2023-06-27 15:23:06
 * @FilePath: \koa-node-ts\app\controller\NavigateController.ts
 * @Description: 
 * undefined
 */

import { Context } from "koa";
import pagination from "../../utils/pagination";
import NavigateService from "../service/NavigateService";
import responese from "../../utils/responese";
import NavigateValidator from "../validator/NavigateValidator";
import validate from "../../utils/validator";

class NavigateController {
  async getPage(ctx: Context) {
    const rows = await NavigateService.getList();

    return responese.success(ctx, rows);
  }

  async addType(ctx: Context) {
    const { data,  msg } = await validate(ctx, NavigateValidator.addRules);
    if(msg) return responese.errorResponese(ctx, msg);
    const [rows, created] = await NavigateService.addType(data);
    if(!created) return responese.errorResponese(ctx, "类型已存在");
    if(rows?.id) return responese.success(ctx, null);
    return responese.errorResponese(ctx, "新增失败");
  }
}

export default new NavigateController;
